﻿using System;

namespace CodeContrib
{
	public sealed class RandomSingleton
	{
		private static volatile RandomSingleton _instance;
		private static readonly object _instanceLock;
		private readonly Random _random;

		public static RandomSingleton Instance
		{
			get
			{
				if (_instance == null)
				{
					lock (_instanceLock)
					{
						_instance = new RandomSingleton();
					}
				}

				return _instance;
			}
		}

		public Random Random
		{
			get { return _random; }
		}

		static RandomSingleton()
		{
			_instanceLock = new object();
		}

		private RandomSingleton()
		{
			_random = new Random(Guid.NewGuid().GetHashCode());
		}
	}
}